package com.droid.network;

import java.util.Map;

import androidx.annotation.NonNull;
import io.reactivex.Observable;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;

/**
 * 网络框架代理
 *
 * @author zhyuc
 * @since 2019/9/26 9:12
 */
public class HttpProxy<T> implements IHttp<T> {

    private final String TAG = "HttpProxy";

    private static volatile HttpProxy mInstance;
    private IHttp mIHttp;

    public static HttpProxy getInstance() {
        if (mInstance == null) {
            synchronized (HttpProxy.class) {
                if (mInstance == null) {
                    mInstance = new HttpProxy();
                }

            }
        }
        return mInstance;
    }

    private HttpProxy() {

    }

    public void init(IHttp iHttp) {
        mIHttp = iHttp;
    }

    @Override
    public Observable<T> get(String url, Map<String, String> parameters) {
        return mIHttp.get(url, parameters);
    }

    @Override
    public Observable<T> post(String url, Map<String, String> parameters) {
        return mIHttp.post(url, parameters);
    }

    @Override
    public Observable<T> post(String url, RequestBody body) {
        return mIHttp.post(url, body);
    }

    @Override
    public Observable<ResponseBody> upload(String url, RequestBody body) {
        return mIHttp.upload(url, body);
    }

    @Override
    public Observable<T> put(@NonNull String url, @NonNull RequestBody body) {
        return mIHttp.put(url, body);
    }

    @Override
    public Observable<T> delete(@NonNull String url, @NonNull Map<String, String> parameters) {
        return mIHttp.delete(url, parameters);
    }

    @Override
    public Observable<ResponseBody> sse(@NonNull String url) {
        return mIHttp.sse(url);
    }
}
